package wt.hpad.utils;

import android.view.View.MeasureSpec;

/**
 * Created by wt on 17-10-23.
 */

public class ViewUtil {

    /**
     * 测量控件的宽度
     *
     * @param measureSpec
     * @return
     */
    public static int measureWidth(int measureSpec) {
        int result = 0;
        int specMode = MeasureSpec.getMode(measureSpec);
        int specSize = MeasureSpec.getSize(measureSpec);

        if (specMode == MeasureSpec.EXACTLY) {  // 精确模式, 也就是范围指定到 dp 级别
            result = specSize;
        } else {
            result = 200;
            if (specMode == MeasureSpec.AT_MOST) {
                result = Math.min(result, specSize);
            }
        }
        return result;
    }

    /**
     * 测量控件的宽度
     *
     * @param measureSpec
     * @return
     */
    public static int measureHeight(int measureSpec) {
        int result = 0;
        int specMode = MeasureSpec.getMode(measureSpec);
        int specSize = MeasureSpec.getSize(measureSpec);

        if (specMode == MeasureSpec.EXACTLY) {  // 精确模式, 也就是范围指定到 dp 级别
            result = specSize;
        } else {
            result = 200;
            if (specMode == MeasureSpec.AT_MOST) {
                result = Math.min(result, specSize);
            }
        }
        return result;
    }
}
